home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Utilities / SoundSwirl / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-12-16  |  2.8 KB  |  156 lines  |  [TEXT/KAHL]

  1. /*
  2. ** main.c
  3. ** 
  4. ** Main control center for the application skeleton
  5. */
  6.  
  7. #include "main.h"        /* general application header */
  8.  
  9. static pascal void restartProc(void);
  10. static void Init(void);
  11. static void MakeWindows(void);
  12. static void SetupMenus(void);
  13.  
  14.  
  15. void main(void)
  16. {
  17.     EventRecord        theEvent;                /* the current event   */
  18.     int                eventMask = everyEvent;    /* current event mask  */
  19.     int                haveEvent;                /* do we have an event */
  20.     long            sleepTime = 0;            /* time to sleep/WNE   */
  21.     Boolean            weHaveWNE=0;            /* do we have MF or 7  */
  22.     
  23.     gMainWindow = NULL;
  24.  
  25.  
  26.     Init();
  27.     InitSound();
  28.     SetupMenus();
  29.     MakeWindows();
  30.     weHaveWNE = TrapAvailable( 0xA860);        /* WaitNextEvent() */
  31.  
  32.     /************* main event loop ****************/
  33.  
  34.     /* HideCursor();    /* */
  35.     while (1) {
  36.         if (weHaveWNE)
  37.         {
  38.             if (WaitNextEvent( eventMask, &theEvent, sleepTime, NULL))
  39.                 DoEvent(&theEvent);
  40.         }
  41.         else
  42.         {
  43.             SystemTask();
  44.             if ( GetNextEvent(eventMask, &theEvent) ) DoEvent(&theEvent);
  45.         }
  46.         
  47.         DrawStep();
  48.     } /* while */
  49. } /* main() */
  50.  
  51.  
  52. /***********************
  53. ** Init()
  54. **
  55. ** This initializes the toolbox
  56. ************************/
  57.  
  58. static void Init()
  59. {
  60.     register int i;
  61.     GrafPtr    windManPort;                /* window manager port */
  62.  
  63.     
  64.     InitGraf(&thePort);
  65.     InitFonts();
  66.     InitWindows();
  67.     InitMenus();
  68.     TEInit();
  69.     InitDialogs(restartProc);        
  70.     InitCursor();
  71.     
  72.     FlushEvents(everyEvent, 0);
  73.  
  74.     for (i=0; i<6; i++) (void)MoreMasters();
  75.     
  76.     GetWMgrPort(&windManPort);
  77.     
  78.     SetPort(windManPort);
  79.     
  80.     SetEventMask(everyEvent);
  81. } /* Init() */
  82.  
  83.  
  84.  
  85. /**********************
  86. ** restartProc()
  87. **
  88. ** This is used for the system error/bomb dialog boxes.
  89. ** Just in case it crashes, we may have a way out.
  90. ***********************/
  91.  
  92. static pascal void restartProc(void)
  93. {
  94.     ExitToShell();
  95. } /* restartProc() */
  96.  
  97.  
  98.  
  99. /***********************
  100. ** SetupMenus()
  101. **
  102. ** loads the menubar and menus.  Adds DAs to apple menu.
  103. ************************/
  104. static void SetupMenus(void)
  105. {
  106.     Handle mbarH;
  107.     
  108.     mbarH = (Handle)GetNewMBar(MENU_BAR);
  109.     if (mbarH == NULL) {
  110.         SysBeep(1); SysBeep(1);
  111.         ExitToShell();
  112.     }
  113.     SetMenuBar( mbarH);
  114.     gAppleM= GetMHandle(APPLE_MENU);
  115.     AddResMenu( gAppleM, 'DRVR');
  116.     gFileM = GetMHandle(FILE_MENU);
  117.     gEditM = GetMHandle(EDIT_MENU);
  118.     gListenM = GetMHandle(LISTEN_MENU);
  119.  
  120.     DisableItem( gListenM, ListenStop);
  121.  
  122.     DrawMenuBar();
  123.     DisposHandle(mbarH);  /* don't need it anymore */
  124. } /* SetupMenus() */
  125.  
  126.  
  127.  
  128. static void MakeWindows(void)
  129. {
  130.     gMainWindow= GetNewWindow( MainWindID, NULL, (WindowPtr)-1L);
  131.     SelectWindow(gMainWindow);
  132.     SetPort( gMainWindow);
  133. } /* MakeWindows() */
  134.  
  135.  
  136. /****************************
  137. ** Cleanup()
  138. **
  139. ** The main program exiting procedure.  It cleans up after
  140. ** ourselves
  141. *****************************/
  142. void Cleanup(void)
  143. {
  144.     DoFileClose();    /* dostuff.c - dispose of any dynamic stuff */
  145.     KillSound();
  146.     ExitToShell();
  147. } /* Cleanup() */
  148.  
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156.